<html>
<head>
<?php 
	//接收window.opne传递过来的用户名
	$username_chat = $_GET['username_chat'];
	//获取loginuser
	session_start();
	$loginuser = $_SESSION['loginuser']
?>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<script type="text/javascript" src="./js/myjs.js"></script>
<script type="text/javascript">
	window.resizeTo(800,700);
	//设置隔一段时间自动取数据
	window.setInterval("getMessage()", 3000);
	var xmlHttpRequest;
	function getMessage(){
		xmlHttpRequest = getXmlHttpObject();
		if(xmlHttpRequest){
			var url = "getMessageController.php";
			var data = "getter=<?php echo $loginuser;?>"+"&sender=<?php echo $username_chat; ?>";
			xmlHttpRequest.open("post", url, true);
			xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlHttpRequest.onreadystatechange=function(){
				if(xmlHttpRequest.readyState==4){
					if(xmlHttpRequest.status==200){
						var meses = xmlHttpRequest.responseXML.getElementsByTagName("mes");
						if(meses.length > 0){
							for(var i=0; i<meses.length; i++){
								$("return_con").value += meses[i].childNodes[1].childNodes[0].nodeValue+"对你说："
										+meses[i].childNodes[3].childNodes[0].nodeValue+"  ["+meses[i].childNodes[4].childNodes[0].nodeValue +"]\r\n";
							}
						}
					}
				}
			};
			xmlHttpRequest.send(data);
		}
	}
	
	function sendMessage(){
		xmlHttpRequest = getXmlHttpObject();
		if(xmlHttpRequest){
			var url = "sendMessageController.php";
			var data="con="+$("con").value+"&getter=<?php echo $username_chat;?>"+"&sender=<?php echo $loginuser;?>";
			xmlHttpRequest.open("post",url,true);
			xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlHttpRequest.onreadystatechange=function(){
				if(xmlHttpRequest.readyState==4){
					if(xmlHttpRequest.status==200){
							if(xmlHttpRequest.responseText == "err"){
								//把发的话显示到聊天框
								$("return_con").value += "error\r\n";
							}
					}
				}
			};
			xmlHttpRequest.send(data);
			$("return_con").value += "你对<?php echo $username_chat;?>"+"说: "+$("con").value+" ["+getNowTime()+"]\r\n";
			$("con").value="";
		}
	}
</script>
</head>
<center>
<h2>聊天室（<font color="red"><?php echo $loginuser;?></font>正在和<font color="red"><?php echo $username_chat;?></font>聊天）</h2>
<br/>
<textarea rows="20" cols="60" id="return_con"></textarea>
<br/>
<br/>
<input type="text" id="con" style="width:300px"/>
<input type="button" value="发送信息" onclick="sendMessage()"/>
</center>
</html>